import { defHttp } from '@/utils/http/axios';
import {
  PageInfo,
  PageParams,
  PageListGetResultModel,
  PageAddReq,
  PageEditReq,
  PageDelReq,
} from './model/pageModel';

enum Api {
  List = '/api/admin/v1/page/list',
  Create = '/api/admin/v1/page/add',
  Update = '/api/admin/v1/page/edit',
  Delete = '/api/admin/v1/page/del',
  Info = '/api/admin/v1/page/info',
}

/**
 * @description: 获取页面列表
 */
export const getPageList = (params: PageParams) =>
  defHttp.get<PageListGetResultModel>({
    url: Api.List,
    params,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

/**
 * @description: 创建页面
 */
export const createPage = (params: PageAddReq) =>
  defHttp.post<{ id: number }>({ url: Api.Create, params });

/**
 * @description: 更新页面
 */
export const updatePage = (params: PageEditReq) => defHttp.put<void>({ url: Api.Update, params });

/**
 * @description: 删除页面
 */
export const deletePage = (params: PageDelReq) => defHttp.delete<void>({ url: Api.Delete, params });

/**
 * @description: 获取页面详情
 */
export function getPageInfo(id: number) {
  return defHttp.get<PageInfo>({
    url: Api.Info,
    params: { id },
  });
}
